/**
 * 
 */
package com.shine.icis.dao.imp;


import org.hibernate.Query;

import com.shine.cotrun.sql.QueryParameters;
import com.shine.cotrun.sql.hibernate.CommQuery;
import com.shine.cotrun.web.comm.ListPage;
import com.shine.icis.dao.ISubmitCalendarDAO;
import com.shine.icis.dao.imp.BaseHibernateDAO;
import com.shine.icis.hbean.SubmitCalendar;
/**
 * 报送日历维护
 * @author zhangxr 2010-12-10
 *
 */
public class SubmitCalendarDAO extends BaseHibernateDAO implements ISubmitCalendarDAO {
	
	/**
	 * 查询报送日历列表，分页显示
	 * @author zhangxr 2010-12-10
	 * @param qp
	 * */
	@SuppressWarnings("unchecked")
	@Override
	public ListPage<SubmitCalendar> findSubmitCalendarPage(QueryParameters qp) {
		if (qp == null) {
			throw new IllegalArgumentException("非法参数:查询参数对象为null");
		}
		try {
			StringBuffer sbQueryString = new StringBuffer();			
			sbQueryString.append("select d from SubmitCalendar as d where 1=1");
			if(qp.getParameter("startDateId") != null){
				sbQueryString.append(" and d.dateId>=:startDateId");
			}
			if(qp.getParameter("endDateId") != null){
				sbQueryString.append(" and d.dateId<=:endDateId");
			}
			return new CommQuery<SubmitCalendar>().queryListPage(qp, 
					qp.appendOrders(sbQueryString, "d" ), getSession());
		} catch(RuntimeException re) {
			re.printStackTrace();
			return new  ListPage<SubmitCalendar>();
		}
	}
	
	/**
	 * 更改报送日历的是否交易日、增量与全量
	 * @author zhangxr 2010-12-10
	 * @param s
	 * */
	public void updateSubmitCalendar(SubmitCalendar s) {
		Query query = getSession().createQuery("update SubmitCalendar s set s.tradeFlag = :tradeFlag,s.incrementFlag=:incrementFlag where s.dateId=:dateId");
		query.setInteger("tradeFlag",s.getTradeFlag());
		query.setInteger("incrementFlag",s.getIncrementFlag());
		query.setInteger("dateId",s.getDateId());
		query.executeUpdate();
	}
}
